import React, { Component } from 'react'
import { HashRouter, withRouter } from 'react-router-dom'
import { renderRoutes } from 'react-router-config'
import IndexPage from '@/pages/index'
import PromotionPage from '@/pages/promotion'
import App from '@/App'

const allRoutes = [
  {
    path: '/index',
    exact: false, // exact表示是否严格匹配
    component: IndexPage
  },
  {
    path: '/promotion',
    exact: false,
    component: PromotionPage
  }
]
// 高阶路由组件（ 获取 location, history 等路由信息 ）
const AppWrap = withRouter(App) // 访问 / 跳转首页
class AppRoute extends Component {
  render() {
    return (
      <HashRouter>
        <AppWrap>
          {renderRoutes(
            allRoutes.map((item) => {
              return { ...item, key: item.path }
            })
          )}
        </AppWrap>
      </HashRouter>
    )
  }
}
export default AppRoute
